library(survey)
library(dplyr)
library(ggplot2)
library(gridExtra)

# Wave 2

summary(factor(df$Q32))
summary(factor(df$AGE7))

df$MOVIES <- NA
df$MOVIES[df$Q32 < 77] <- 0
df$MOVIES[df$Q32 == 2] <- 1
summary(factor(df$MOVIES))

df$AGE2[df$AGE7 < 77] <- 1
df$AGE2[df$AGE7 < 3] <- 0

df$Q11T <- NA
df$Q11T[df$Q11 > 2 & df$Q11 < 77] <- 0
df$Q11T[df$Q11 < 3] <- 1
summary(factor(df$Q11T))

df2 <- df[!is.na(df$MOVIES),]
df2 <- df2[!is.na(df2$Q11T),]
summary(factor(df2$MOVIES))
summary(factor(df2$Q11T))

# Create Survey design
w2_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight2,
    data = df2
  )


# Calculate the mean confidence by age group and info type
svymean(~Q11T,design = w2_design[w2_design$variables$MOVIES==0 & w2_design$variables$AGE2==0])
mean(w2_design$variables$Q11T[w2_design$variables$MOVIES==0 & w2_design$variables$AGE2==0])
mean(w2_design$variables$Q11T[w2_design$variables$MOVIES==1 & w2_design$variables$AGE2==0])

mean(w2_design$variables$Q11T[w2_design$variables$MOVIES==0 & w2_design$variables$AGE2==1])
mean(w2_design$variables$Q11T[w2_design$variables$MOVIES==1 & w2_design$variables$AGE2==1])
